package com.quanxi.qxaimain.controller.v1.indicators;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.quanxi.qxaimain.model.indicators.ProducePargram;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/indicators")
@Api(tags = "指标")
public class UseProcController {
    @Resource
    com.quanxi.qxaimain.model.indicators.indicatorsGet indicatorsGet;

    @PostMapping("/singleDiseaseDetail")
    @ApiOperation(value = "显示单个病种的明细", httpMethod = "POST")
    @ApiImplicitParams({@ApiImplicitParam(name = "params" ,value = "参数格式: json; 参数: start_date, end_date, disease_code: 疾病编码, dept_name: 科室名称 ",
            required = true, dataType = "json", paramType = "body")})
    public JSONObject singleDiseaseDetail (@RequestBody JSONObject params) throws ParseException {
        JSONObject data = params.getJSONArray("data").getJSONObject(0);
        String start_date = data.getString( "start_date");
        String end_date = data.getString( "end_date");
        String disease_code = data.getString("disease_code");
        String dept_name = data.getString("dept_name");



        Map<String, Object> map = new HashMap<>();
        map.put("produceName", "PROC_YY421");
        map.put("D1", start_date);
        map.put("D2", end_date);
        map.put("P1", disease_code);
        map.put("DEPT_NAME", dept_name);


        JSONObject produceresult = indicatorsGet.getProduceresult(map);
        List<LinkedHashMap<String, Object>> o = (List<LinkedHashMap<String, Object>>) map.get("p_cur");      //转哈希
        String result = JSON.toJSONString(o, SerializerFeature.WriteMapNullValue);                           //保留null

        log.info(produceresult.toJSONString());
        log.info(result);
        return produceresult;
//        System.out.println("美化格式输出:");
//
    }
}
